package com.routz.shiro_demo.user_password_sample.web;

import com.routz.shiro_demo.user_password_sample.entity.User;
import com.routz.shiro_demo.user_password_sample.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class UserController {

    // 注册
    @PostMapping("/signup")
    public void signUp(@ModelAttribute User user) {
        userService.signUp(user);
    }

    // 登录
    @PostMapping("/login")
    public void login(@ModelAttribute User user) {
        userService.login(user);
    }

    @GetMapping("/home")
    public List<User> home() {
        return userService.list();
    }

    @GetMapping("/error")
    public String error() {
        return "Invalid username and password.";
    }

    @Autowired
    private UserService userService;
}
